package com.mindbook.vip.gawxchatinfo.controller.nostrum;

import com.mindbook.vip.gawxchatinfo.entity.nostrum.FunctionLink;
import com.mindbook.vip.gawxchatinfo.service.nostrum.FunctionLinkService;
import com.mindbook.vip.gawxchatinfo.utils.crud.CrudUtils;
import com.mindbook.vip.gawxchatinfo.utils.result.Result;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultEnum;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "功能连接")
@RestController
@RequestMapping("/nostrum/function/link")
public class FunctionLinkController {

    @Autowired private FunctionLinkService functionLinkService;

    @PostMapping("/")
    @ApiOperation(value = "新增")
    public Result add(FunctionLink functionLink){
        Integer add = functionLinkService.add(functionLink);

        CrudUtils.validateAddResult(add);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_ADD_SUCCESS.getMsg());
    }

    @PutMapping("/")
    @ApiOperation(value = "修改")
    public Result update(FunctionLink functionLink){
        Integer put = functionLinkService.put(functionLink);

        CrudUtils.validateUpdateResult(put);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_UPDATE_SUCCESS.getMsg());
    }

    @ApiOperation("查询所有的数据列表")
    @GetMapping("/list")
    public Result findAll(){
        List<FunctionLink> all = functionLinkService.findAll();

        return ResultUtils.genSuccessResult(all);
    }

    @GetMapping("/{id}/{nostrumFunctionidId}")
    @ApiOperation("查询详情")
    public Result findByIdAndNostrumFunctionId(@PathVariable Integer id,@PathVariable Integer nostrumFunctionidId){
        FunctionLink byIdAndNostrumFunctionId = functionLinkService.findByIdAndNostrumFunctionId(id, nostrumFunctionidId);

        return ResultUtils.genSuccessResult(byIdAndNostrumFunctionId);
    }

    @DeleteMapping("/{id}/{nostrumFunctionidId}")
    @ApiOperation("删除")
    public Result delete(@PathVariable Integer id,@PathVariable Integer nostrumFunctionidId){
        Integer remove = functionLinkService.remove(id, nostrumFunctionidId);

        CrudUtils.validateDeleteResult(remove);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_DELETE_SUCCESS.getMsg());
    }

}
